home *** CD-ROM | disk | FTP | other *** search
- /* 86WORLD Figure 10 - Font Conversion
- Micro Cornucopia Magazine Issue #46 */
-
- /*-- Fill in a Windows Font Header from a Gem Font Header --*/
-
- void ConvertG2W( )
- { /* assumes all data is in previously defined global arrays */
- int numchars = (GemFont.gfLastChar - GemFont.gfFirstChar + 1);
-
- /* Translate the header information */
- WinFont.dfVersion = 256;
- strnset(WinFont.dfCopyright,'c',60);
- WinFont.dfType = 0;
- WinFont.dfPoints = GemFont.gfFormHeight;
- WinFont.dfVertRes = 72;
- WinFont.dfHorizRes = 72;
- WinFont.dfAscent = GemFont.gfTopLine;
- if (WinFont.dfAscent == 0)
- WinFont.dfAscent = GemFont.gfAscentLine;
- WinFont.dfInternalLeading = 0;
- WinFont.dfExternalLeading = 0;
- WinFont.dfItalic = 0;
- WinFont.dfUnderline = 0;
- WinFont.dfStrikeOut = 0;
- WinFont.dfWeight = 200;
- WinFont.dfCharSet = 255;
- WinFont.dfPixWidth = 0;
- WinFont.dfPixHeight = GemFont.gfFormHeight;
- WinFont.dfPitchAndFamily = 1; /* low bits indicates proportional */
- WinFont.dfAvgWidth = chofstable['X'+1-GemFont.gfFirstChar]
- - chofstable['X'-GemFont.gfFirstChar];
- WinFont.dfMaxWidth = MaxWidthInTable(chofstable, numchars);
- WinFont.dfFirstChar = GemFont.gfFirstChar;
- WinFont.dfLastChar = GemFont.gfLastChar;
- WinFont.dfDefaultChar = 0x60 - GemFont.gfFirstChar;
- WinFont.dfBreakChar = 32 - GemFont.gfFirstChar;
- WinFont.dfWidthBytes = GemFont.gfFormWidth;
- WinFont.dfDevice = 0;
- WinFont.dfBitsPointer = 0;
- WinFont.dfBitsOffset = (((sizeof(WinFont) && 1) == 1) ?
- sizeof(WinFont)+1 : sizeof(WinFont))
- + ((numchars+1)*2);
- WinFont.dfFace = WinFont.dfBitsOffset
- + (WinFont.dfWidthBytes * WinFont.dfPixHeight);
- /* NOTE: The following is out of sequence because it depends on
- other computed values in the header */
- strncpy(facename,GemFont.gfName,17);
- facename[16] = 0;
- WinFont.dfSize = WinFont.dfFace + strlen(facename)+1;
- } /* ConvertG2W */
-
- /*-- Fill in a Gem Font Header from a Windows Font Header --*/
-
- void ConvertW2G( )
- { /* assumes all data is in previously defined global arrays */
- int numchars = (WinFont.dfLastChar - WinFont.dfFirstChar + 1);
-
- /* Translate the header information */
- GemFont.gfID = 2;;
- GemFont.gfPointSize = WinFont.dfPoints;
- strcpy(GemFont.gfName,facename);
- GemFont.gfFirstChar = WinFont.dfFirstChar;
- GemFont.gfLastChar = WinFont.dfLastChar;
- GemFont.gfTopLine = WinFont.dfAscent;
- GemFont.gfAscentLine = WinFont.dfAscent;
- GemFont.gfHalfLine = WinFont.dfAscent/2+1;
- GemFont.gfDescentLine = WinFont.dfPixHeight-WinFont.dfAscent-1;
- GemFont.gfBottomLine = WinFont.dfPixHeight-WinFont.dfAscent;
- GemFont.gfMaxWidth = WinFont.dfMaxWidth;
- GemFont.gfMaxCellWidth = WinFont.dfMaxWidth;
- GemFont.gfLeftOffset = 0;
- GemFont.gfRightOffset = 0;
- GemFont.gfThickening = 1;
- GemFont.gfUndlSize = 1;
- GemFont.gfLightMask = 0x5555;
- GemFont.gfSkewMask = 0x5555;
- GemFont.gfFlags = 0;
- GemFont.gfHorOfsTable = 0;
- GemFont.gfCharOfsTable = ((sizeof(GemFont) && 1) == 1) ?
- sizeof(GemFont)+1 : sizeof(GemFont);
- GemFont.gfBitsOffset = GemFont.gfCharOfsTable + ((numchars+1)*2);
- GemFont.gfFormWidth = WinFont.dfWidthBytes;
- GemFont.gfFormHeight = WinFont.dfPixHeight;
- GemFont.gfNextFont = 0;
- if (WinFont.dfPixWidth != 0) /* if fixed pitch in Windows */
- MakeChOfsTable(chofstable, WinFont.dfPixWidth, numchars);
- } /* ConvertW2G */
-
- /*-- determine size of a file --*/
-
- long fsize(FILE* fp)
- { /* this was written because there is not an ANSI */
- /* standard fsize(). Every compiler has a different one */
- /* This one uses only ANSI routines */
- long tmpsize;
- long pos = ftell(fp);
- fseek(fp, 0L, SEEK_END);
- tmpsize = ftell(fp);
- fseek(fp, pos, SEEK_SET);
- return(tmpsize);
- } /* fsize */
-
- /*-- Determine if file is a Windows FNT file --*/
-
- int IsWindowsFont(char filename[])
- {
- int temp;
- long size;
-
- FILE* fin = fopen(filename,"rb");
- fread(&temp,2,1,fin); /* read past version */
- fread(&size,4,1,fin);
- /* read long word in byte 2-5 and see if = length of file */
- temp = (fsize(fin) == size);
- fclose (fin);
- return(temp);
- } /* IsWindowsFont */
-
- /*-- Construct a character offset table --*/
-
- void MakeChOfsTable(int ChOfsTable[], int Width, int NumChars)
- {
- for (int ct = 0; ct <= NumChars; ct++)
- ChOfsTable[ct] = ct*Width;
- } /* MakeChOfsTable */